package com.zr.serviceimpl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.zr.dao.SerachUsersByInfoDao;
import com.zr.model.Cuser;
import com.zr.service.SerachUsersByInfoService;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

@Service("serachUsersByInfoService")
public class SerachUsersByInfoServiceImpl implements SerachUsersByInfoService{
         
	@Resource
	private SerachUsersByInfoDao<Cuser> serachUsersByInfoDao;

	@Override
	public JSONObject getUsersByInfo(int page, int rows, String searType, String sertInfo) {
		JSONObject j = new JSONObject();
		j.put("total", serachUsersByInfoDao.getUsersCountByInfo(searType, sertInfo));
		List<Cuser> us = serachUsersByInfoDao.getUsersByInfo(page, rows, searType, sertInfo);
		JSONArray js = new JSONArray();
		for (Cuser uu : us) {
			JSONObject u = new JSONObject();
			u.put("uid", uu.getUid());
			u.put("uname", uu.getUname());
			u.put("utel", uu.getUtel());
			u.put("ustate", uu.getUstate());
			u.put("rname", uu.getCrole().getRname());
			js.add(u);
		}
		j.put("rows", js);
		return j;
	}
}
